
const request = require('../libs/request.js')

/**
 * 获取严选配置
 * @returns {Promise<Object>}
 */
const config = async () => {
    try {
        const response = await request.authGet('/v1/store/config')

        if (response.code === 1) {
            return {
                success: true,
                data: response.data,
                message: response.msg
            }
        } else {
            throw new Error(response.msg || '获取严选配置失败')
        }
    } catch (error) {
        return {
            success: false,
            message: error.message
        }
    }
}

/**
 * 获取推荐商品列表
 * @returns {Promise<Object>}
 */
const recommendGoodsList = async (tag) => {
    try {
        const response = await request.get('/v1/store/recommendGoodsList',{
            showLoading:true,
            needAuth:false,
            data:{
                type:tag
            }
        })

        if (response.code === 1) {
            return {
                success: true,
                data: response.data,
                message: response.msg
            }
        } else {
            throw new Error(response.msg || '获取推荐商品列表失败')
        }
    } catch (error) {
        return {
            success: false,
            message: error.message
        }
    }
}

/**
 * 获取自提点列表
 */
const pickUpPointList = async () => {
    try {
        const response = await request.get('/v1/store/pickUpPointList',{
            showLoading:false,
            needAuth:false,
        })

        if (response.code === 1) {
            return {
                success: true,
                data: response.data,
                message: response.msg
            }
        }
        else {
            throw new Error(response.msg || '获取自提点列表失败')
        }
    }catch (error) {
        return {
            success: false,
            message: error.message
        }
    }
}

module.exports = {
    config,
    recommendGoodsList,
    pickUpPointList
} 